/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-05-11 22:12:11
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-05-11 23:35:25
 * @FilePath: /gptfront-dev/src/components/DrawerContent/hooks.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { computed } from 'vue'
import { useStore } from 'vuex'
import { getRoomList } from '@/api/chat'
import useAIModelStore from '@/store/modules/AIModel'
// DrawerContent  hooks
export function useAIModel(emit) {
  const AIModelStore = useAIModelStore()
  const AIModels = computed(() => AIModelStore.AIModels)
  const AIModel = computed(() => AIModelStore.AIModel)

  function toggleModelAction(value) {
    emit('close')
    uni.redirectTo({
      url: `/pages/index/index?chatMode=${value}`,
    })
  }
  return {
    AIModel,
    AIModels,
    toggleModelAction,
  }
}

export function useConversations(emit) {
  const store = useStore()
  const conversations = computed(() => store.state.chat.roomList)
  const AIModelStore = useAIModelStore()

  function toggleConversationAction(room) {
    emit('close')
    AIModelStore.toggleByVersion(3)
    uni.redirectTo({
      url: `/pages/index/index?room=${room.id}`,
    })
  }
  function getConversations({ page, limit }) {
    return getRoomList({ page, size: limit })
  }

  return {
    conversations,
    toggleConversationAction,
    getConversations,
  }
}
